from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers
from goods.models import SKU
from goods.search_indexes import SKUIndex


class SKUSerializers(serializers.ModelSerializer):
    """
    SKＵ序列化器
    """
    class Meta:
        model = SKU
        # fields = ('id', 'name', 'price', 'default_image_url', 'comments')
        fields = '__all__'


class SKUIndexSerializers(HaystackSerializer):
    """
    SKU索引结果数据序列化器
    """
    object = SKUSerializers(read_only=True)

    class Meta:
        index_classes = [SKUIndex]   # 指定索引类
        fields = ('text', 'object')
